package com.dd.demo01.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author: lkd
 * @date: 2023/04/30/16:42
 * @Description:
 */
@Component
@Aspect
@Order(value = 4)
public class TestAspect {

	// 环绕前置–>普通前置–>目标方法执行–>环绕正常结束/出现异常–>环绕后置–>普通后置–>普通返回或者异常。

	@Pointcut("@annotation(com.dd.demo01.aop.annotation.TestAop)")
	public void point() {
	}

	@Around("point()")
	public Object around(ProceedingJoinPoint pjp) throws Throwable {
		System.out.println("around----前");
		Object result = null;
		try {
			result = pjp.proceed();
		} catch (Throwable e) {
			System.out.println("TestAspect直接捕获了异常");
		}
		System.out.println("around----后");
		return result;
	}

	@Before("point()")
	public void before() {
		System.out.println("----before---");
	}

	@After("point()")
	public void after() {
		System.out.println("---after---");
	}

	@AfterReturning("point()")
	public static void stop() {
		System.out.println("---AfterReturning---");

	}

	@AfterThrowing("point()")
	public static void logException() {
		System.out.println("---AfterThrowing---");
	}


}
